/**
 *博尔信基础开发平台
 *<br> 版权声明：厦门博尔信软件有限公司版权所有,违者必究
 *<br> Copyright:  Copyright (c) 2012
 *<br> Company:pearlsoft
 *<br> @author 蒋勇华
 *<br> 2012-5-10
 *<br> @version 1.0
 *————————————————————————————————————
 *修改记录
 *    修改者：
 *    修改时间：
 *    修改原因：
 *——————————————————————————————————————
 */
package com.pearlsoft.webapp.rms.resapply;

import org.apache.commons.lang.StringUtils;

import com.pearlsoft.webapp.core.annotation.DataSetHandlerComponent;
import com.pearlsoft.webapp.core.dataset.DataSet;
import com.pearlsoft.webapp.core.dataset.Record;
import com.pearlsoft.webapp.core.dataset.Result;
import com.pearlsoft.webapp.core.web.basehandler.AbsDataSetHandler;
import com.pearlsoft.webapp.core.web.session.SessionProfile;
import com.pearlsoft.webapp.rms.resapply.service.ResApplyService;

/**
 *描述： 
 *
 * 
 */
@DataSetHandlerComponent(name = "ResApplyDataSetHandler")
public class ResApplyDataSetHandler extends AbsDataSetHandler{


	@Override
	public void handler(DataSet ds, Result result) throws Exception {
		
	}


	@Override
	public void save(DataSet ds, Result result) throws Exception {
		//new String(Base64.decodeBase64(cookie.getValue().getBytes()))
		String userId = this.getDecodeCookieValue(SessionProfile.COOKIE_USERID)	;
		Record record = ds.getCurrentRecord();
		record.setValue("authorId", userId);
		ResApplyService resApplyService = this.getBean("resApplyService", ResApplyService.class);
		resApplyService.save(record);
		result.getRecords().add(record);
	}

	public void submitApply(DataSet ds, Result result) throws Exception {
		String userId = this.getDecodeCookieValue(SessionProfile.COOKIE_USERID)	;
		Record record = ds.getCurrentRecord();
		record.setValue("authorId", userId);
		ResApplyService resApplyService = this.getBean("resApplyService", ResApplyService.class);
		resApplyService.apply(record);
		result.getRecords().add(record);
	}
	
	@Override
	public void delete(DataSet ds, Result result) throws Exception {
		ResApplyService resApplyService = this.getBean("resApplyService", ResApplyService.class);
		String orgId = (String) ds.getConditions().get("objId");
		resApplyService.deleteById(orgId);
	}


	@Override
	public void deleteAll(DataSet ds, Result result) throws Exception {
		ResApplyService resApplyService = this.getBean("resApplyService", ResApplyService.class);
		String objIds = (String) ds.getConditions().get("objIds");
		String[] ids = objIds.split(",");
		for(String id:ids){
			if( !StringUtils.isBlank(id)){
				resApplyService.deleteById(id);
			}
		}
	}

}
